package com.example.demo.controller;

import com.example.demo.entity.Menu;
import com.example.demo.service.RoleMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * @author moguai
 * @version 1.0
 * @date 2022/3/20 11:33
 */
@RestController
@RequestMapping("/api")
@Api(tags = "菜单")
public class MenuController {
    @Autowired
    @Qualifier(value = "roleMenuServiceImpl")
    RoleMenuService role_menuService;

    @ApiOperation("获取用户权限菜单")
    @GetMapping("/menus")
    public List<Menu> getMenus(HttpServletRequest request) {
        HttpServletRequest req = (HttpServletRequest) request;
        Integer id = (Integer) req.getAttribute("userId");
        return role_menuService.selectMenuByUser(id);
    }
}
